package com.txc.pay.enums;

import lombok.Getter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @EnumName: PayTypeEnum
 * @Description: 支付方式枚举类
 * @Author: TXC
 * @Date: 2023-12-26 16:26
 **/
@Getter
public enum PayMethodEnum {
    /**
     * 支付宝支付
     */
    ALINATIVEPAY(PayType.ALIPAY.getValue(), "native", "aliNativePay", "支付宝扫码支付"),
    ALIJSAPIPAY(PayType.ALIPAY.getValue(), "jsapi", "aliJsapiPay", "支付宝网站支付"),
    /**
     * 微信支付
     */
    WXNATIVE(PayType.WECHAT.getValue(), "native", "wxNativePay", "微信扫码支付"),
    WXJSAPI(PayType.WECHAT.getValue(), "jsapi", "wxJsapiPay", "微信网站支付");
    /**
     * 银联支付
     */
   // UNIONPAY("UNIONPAY", "", "", "银联支付");

    public final String value;
    public final String method;
    public final String service;
    public final String name;

    PayMethodEnum(String value, String method, String service, String name) {
        this.value = value;
        this.method = method;
        this.service = service;
        this.name = name;
    }

    public static PayMethodEnum getEnum(String value, String type) {
        for (PayMethodEnum payTypeEnum : PayMethodEnum.values()) {
            if (payTypeEnum.getValue().equals(value) && payTypeEnum.getMethod().equals(type)) {
                return payTypeEnum;
            }
        }
        return null;
    }

    public Map<String, String> toMap() {
        Map<String, String> map = new HashMap<>();
        map.put("method",this.getMethod());
        map.put("name",this.getName());
        return map;
    }

    public static List<Map<String, String>> getEnum(String value) {
        List<Map<String, String>> result = new ArrayList<>();
        for (PayMethodEnum payTypeEnum : PayMethodEnum.values()) {
            if (payTypeEnum.getValue().equals(value)) {
                Map<String, String> map = payTypeEnum.toMap();
                result.add(map);
            }
        }
        return result;
    }
}
